/**
 * This controller manages the User details view which are added as tabs (so multiple
 * instances are created). Each instance of the view creates an instance of this class to
 * control its behavior.
 */
Ext.define('DCApp.view.img.DetailController', {
    extend: 'Ext.app.ViewController',
    alias: 'controller.imgdetail',

    requires: [
        'Ext.window.Toast'
    ],
    onBackClick: function() {
    	 //this.redirectTo("imglist")
    	Ext.util.History.back();
    },    
    onSaveClick: function() {
        var form = this.lookupReference('form'),
            rec;
        
        if (form.isValid()) {
            rec = this.getViewModel().get('theImg');
            Ext.Msg.wait('保存', '保存文稿中...');
        	DCApp.Cfg.addStores({
        		'image_imgType':rec.get('imgType'),
        		'image_imageSource':rec.get('imageSource'),
        		'image_imgColor':rec.get('imgColor')
        	});
            rec.save({
                scope: this,
                callback: this.onComplete
            });
        }
    },

    onComplete: function() {
        Ext.Msg.hide();
        Ext.toast({
            title: '保存',
            html: '影像保存完成',
            align: 't',
            bodyPadding: 10
        });
        this.redirectTo("imglist");
    },
    onNext: function() {
    	var token = Ext.util.History.getToken();
    	var pos = token.lastIndexOf('/');
    	var sid= parseInt(token.substring(pos+1));
    	sid++;
    	if(sid>DCApp.Cfg.SIM_ENM['Image'])
    		sid=1;
    	this.redirectTo(token.substring(0,pos+1)+sid);
    },
    onPrev: function() {
    	var token = Ext.util.History.getToken();
    	var pos = token.lastIndexOf('/');
    	var sid= parseInt(token.substring(pos+1));
    	sid--;
    	if(sid<1)
    		sid=DCApp.Cfg.SIM_ENM['Image'];
    	this.redirectTo(token.substring(0,pos+1)+sid);
    }
});
